﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Goldlight.Mvvm.Base;
using System.Windows.Input;
using Goldlight.Mvvm.Base.Command;
using Goldlight.SampleApplication.Model;
using System.Diagnostics;
using Goldlight.SampleApplication.ViewModels.Marketing;

namespace Goldlight.SampleApplication.ViewModels.NavigationPanel
{
    public class MarketingNavigationViewModel : ViewModelBase
    {
        private LanguageResources.Language _resources;
        private List<CommandModel> _commands;
        private bool _selected;

        /// <summary>
        /// Initialize a new instance of <see cref="MarketingNavigationViewModel"/>.
        /// </summary>
        public MarketingNavigationViewModel() : base()
        {
            _resources = new LanguageResources.Language();

            _commands = new List<CommandModel>();

            AddCommand(LanguageResources.Language.AccountsHeading, () => TriggerAccount());
            AddCommand(LanguageResources.Language.CampaignsHeading, () => TriggerCampaign());
            AddCommand(LanguageResources.Language.ContactsHeading, () => TriggerContacts());
            AddCommand(LanguageResources.Language.LeadsHeading, () => TriggerDummy());
            AddCommand(LanguageResources.Language.MarketingListsHeading, () => TriggerDummy());
            AddCommand(LanguageResources.Language.ProductsHeading, () => TriggerDummy());
            AddCommand(LanguageResources.Language.QuickCampaignsHeading, () => TriggerDummy());
            AddCommand(LanguageResources.Language.SalesLiteratureHeading, () => TriggerDummy());
        }

        private void AddCommand(string label, Action action)
        {
            _commands.Add(new CommandModel(label, action));
        }

        /// <summary>
        /// Get a list of the commands.
        /// </summary>
        public List<CommandModel> Commands
        {
            get { return _commands; }
        }

        /// <summary>
        /// Get or set whether the item has been selected.
        /// </summary>
        public bool IsSelected
        {
            get
            {
                return _selected;
            }
            set
            {
                if (_selected != value)
                {
                    _selected = value;
                    OnChanged(() => IsSelected);
                }
            }
        }

        /// <summary>
        /// Get the resources object.
        /// </summary>
        public override object Resources
        {
            get
            {
                return _resources;
            }
        }



        private void TriggerAccount()
        {
            Debug.WriteLine("Inside trigger");
        }

        private void TriggerCampaign()
        {
        }

        private void TriggerContacts()
        {
            ContactViewModel cvm = WorkspaceManager.FindWorkspace<ContactViewModel>();
            if (cvm == null)
            {
                cvm = new ContactViewModel();
                WorkspaceManager.AddWorkspace(cvm);
            }
            else
            {
                WorkspaceManager.SetActiveWorkspace(cvm);
            }
        }

        private void TriggerDummy()
        {
        }

    }
}
